//
//  HomeButton.m
//  xpkc
//
//  Created by wanmeizty on 14/12/24.
//  Copyright (c) 2014年 wanmeizty. All rights reserved.
//

#import "HomeButton.h"

@implementation HomeButton{
    UILabel *inFlag;
    UIImageView *titleImg;
    UILabel *buttonTitleLabel;
}

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatHomeButtonView];
    }
    return self;
}

- (void)creatHomeButtonView{
    CGFloat btnW = self.frame.size.width;
    CGFloat btnH = self.frame.size.height;
    self.backgroundColor = [UIColor clearColor];
    titleImg = [[UIImageView alloc]initWithFrame:CGRectMake(btnW/4, btnW/4-10, btnW/2, btnW/2)];
    
    [self addSubview:titleImg];
    
    //
    buttonTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, btnH-45, btnW-20, 45)];
    buttonTitleLabel.textColor = [UIColor whiteColor];
    buttonTitleLabel.textAlignment = NSTextAlignmentCenter;
    buttonTitleLabel.font = FONT_SYS(14);
    [self addSubview:buttonTitleLabel];
    
    //添加标记
    inFlag = [[UILabel alloc]initWithFrame:CGRectMake(btnW-10, 0, 10, 10)];
    inFlag.text = @"+";
    inFlag.textColor = [UIColor redColor];
    inFlag.hidden = YES;
    [self addSubview:inFlag];
    
//    self.layer.borderWidth = 1;
}

- (void)setValueWithDic:(NSDictionary *)dic{
    buttonTitleLabel.text = [dic objectForKey:@"title"];
    titleImg.image = [UIImage imageNamed:[dic objectForKey:@"image"]];
}
- (void)setValue{
    buttonTitleLabel.text = self.buttonTitle;
}

- (void)isInHome:(BOOL)isIn{
    if (isIn) {
        inFlag.hidden = YES;
    }else{
        inFlag.hidden = NO;
    }
}
- (void)setStyle:(HomeButtonStyle)homeButtonStyle{
    switch (homeButtonStyle) {
        case HomeButtonStyleDefault:
            self.backgroundColor = [UIColor whiteColor];
            buttonTitleLabel.textColor = [UIColor blackColor];
            break;
        case HomeButtonStyleLightGray:
            self.backgroundColor = [UIColor lightGrayColor];
            buttonTitleLabel.textColor = [UIColor whiteColor];
            break;
        case HomeButtonStyleLight:
            self.backgroundColor = [UIColor whiteColor];
            buttonTitleLabel.textColor = [UIColor blackColor];
            
        default:
            break;
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
